﻿using System.Collections.Generic;
using ActionGraph.Core;
using UnityEngine;

public static class EntityUtils
{
    //Todo:抽离函数
    public static GameEntity CreatePlayerEntity (Contexts context,Vector2 pos,Vector2 vel,float angle=0)
    {
        var playerEntity = context.game.CreateEntity ();
        playerEntity.isPlayerTag = true;
        playerEntity.AddPosComp (Vector2.zero);
        playerEntity.AddVelComp (Vector2.zero);
        playerEntity.AddRotComp (0f);
        playerEntity.isPhysicsTag = true;
        playerEntity.AddCreateViewCmdComp (ActorTag.Player);
        
        playerEntity.AddTimerComp (0f);
        
        //Test
        var host=new ActionGraphHost ();
        host.SetData (Resources.Load<ActionGraph.Core.ActionGraph> ("HelloGraph"),playerEntity);
        playerEntity.AddActionComp (new List<ActionGraphHost>
        {
            host
        });

        return playerEntity;
    }

    public static GameEntity CreateBulletEntity (Contexts context,Vector2 pos,Vector2 vel,float angle)
    {
        var bulletEntity = context.game.CreateEntity ();
        bulletEntity.isBulletTag = true;
        bulletEntity.AddPosComp (pos);
        bulletEntity.AddVelComp (vel); 
        bulletEntity.AddCreateViewCmdComp (ActorTag.Bullet);
        bulletEntity.AddRotComp (angle);
        bulletEntity.isPhysicsTag = true;
        bulletEntity.AddLifeTimeComp (2);
        return bulletEntity;
    }
    
    public static GameEntity CreateEnemyEntity (Contexts context,Vector2 pos,Vector2 vel,float angle)
    {
        var enemytEntity = context.game.CreateEntity ();
        enemytEntity.isEnemyTag = true;
        enemytEntity.AddPosComp (pos);
        enemytEntity.AddVelComp (vel); 
        enemytEntity.AddCreateViewCmdComp (ActorTag.Enemy);
        enemytEntity.isPhysicsTag = true;
        enemytEntity.AddRotComp (angle);
        return enemytEntity;
    }
}